n=int(input())
nums=list(map(int,input().split()))

smax=nums[0]
smin=nums[0]

m=nums[0]

for i in range(1,n):
    smax+=max(nums[i],m)
    if nums[i]>m:
        smin+=nums[i]
    else:
        smin+=0
    m=max(nums[i],m)

print(smax)
print(smin)



